package com.cf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cf.domain.ResponseResult;
import com.cf.domain.pojo.Judges;
import com.cf.domain.pojo.PageQuery;
import com.cf.service.IJudgesService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author lzqinga@126.com
 * @Date 2024/11/9  10:08
 */
@Controller
@RequiredArgsConstructor
@RequestMapping("/judge")
public class JudgesController {

    private final IJudgesService judgesService;
    /**
     * 添加
     */
    @PostMapping
    @ResponseBody
    public ResponseResult save(@RequestBody Judges judges){
        judgesService.save(judges);
        return ResponseResult.sucess();
    }

    @PutMapping
    @ResponseBody
    public ResponseResult update(@RequestBody Judges judges){
        judgesService.updateById(judges);
        return ResponseResult.sucess();
    }

    @GetMapping("/{id}")
    @ResponseBody
    public ResponseResult getById(@PathVariable Long id){
        Judges judges = judgesService.getById(id);
        return ResponseResult.sucess(judges);
    }

    @GetMapping("/pagination")
    @ResponseBody
    public ResponseResult getAll(@RequestParam(defaultValue = "0") Integer pageNo,
                                 @RequestParam(defaultValue = "10") Integer pageSize){
        PageQuery pageQuery = new PageQuery(Integer.valueOf(pageNo), pageSize);
        Page<Judges> data = judgesService.selectAllJudges(pageQuery);
        return ResponseResult.sucess(data);
    }

    @DeleteMapping("/{id}")
    @ResponseBody
    public ResponseResult deleteById(@PathVariable Long id){
        Judges judges = new Judges();
        judges.setId(id);
        judges.setEnable(1);
        judgesService.updateById(judges);
        return ResponseResult.sucess();
    }
}
